package cao.oschina.function;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import cao.oschina.app.AppContext;
import cao.oschina.ui.Main;

/**
 * 功能fragment
 * <p/>
 * <p/>
 * Created by Haidy on 15/4/3.
 */
public abstract class FunctionFragment extends Fragment {

    protected final Main main;
    protected final AppContext app;

    public FunctionFragment(Main main) {
        super();
        this.main = main;
        this.app = main.app;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(createView(), null);
        initView(view);
        initData();
        return view;
    }

    /**
     * 要创建的视图
     *
     * @return view
     */
    protected abstract int createView();

    /**
     * 初始化界面
     *
     * @param view view
     */
    protected abstract void initView(View view);

    /**
     * 初始化数据
     */
    protected abstract void initData();

}
